package com.shangxia.monomer.common.util;

import com.shangxia.monomer.common.content.SystemContent;
import com.shangxia.monomer.common.content.typeEnum.ImageTypeEnum;

import javax.imageio.ImageIO;
import java.awt.*;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;

/**
 * @author zhouya38158
 * @Package com.shangxia.monomer.common.util
 * @date 2021/7/22 9:51
 */
public class MediaUtil {
    public static void main(String[] args) throws IOException, AWTException {
        captureScreen("截图", ImageTypeEnum.PNG);
    }

    /**
     * 截图
     *
     * @param filename
     * @throws AWTException
     * @throws IOException
     * @throws IOException
     */
    public static void captureScreen(String filename, ImageTypeEnum type) throws AWTException, IOException, IOException {
        Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
        Rectangle screenRectangle = new Rectangle(screenSize);
        Robot robot = new Robot();
        BufferedImage image = robot.createScreenCapture(screenRectangle);
        filename = SystemContent.PATH + filename + "." + (System.currentTimeMillis() + "").substring(9, 13) + "." + type.name();
        ImageIO.write(image, type.name(), new File(filename));
    }
}
